package com.morgan.maxfinance;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class DeclineActivity extends Activity {

	Button btnExit;
	LinearLayout llytHeader;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.decline_page);
        
        initWidget();
        initValue();
        initEvent();
    }
    
    private void initWidget() {
		llytHeader = (LinearLayout) findViewById(R.id.header_linearLayout);

    	btnExit = (Button) findViewById(R.id.exit_button);
    }
    
    private void initValue() {

    }
    
    private void initEvent() {
    	
		llytHeader.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maxfinance.com.au"));
				startActivity(browserIntent);
			}
        });
		
    	btnExit.setOnClickListener(new Button.OnClickListener() {

 			@Override
 			public void onClick(View v) {
 				exitApp();
 			}
         });
    }

    public void onBackPressed() {
    	exitApp();
    }
    
    public void exitApp() {
    	
    	new AlertDialog.Builder(this)
        .setTitle("Exit App")
        .setMessage("Are u sure you want to exit app?"
        )
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // continue with delete
        		Intent intent = new Intent(DeclineActivity.this, MainActivity.class);
        	    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        	    intent.putExtra("Exit me", true);
        	    startActivity(intent);
        	    finish();
            }
         })
         .setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // continue with delete
            }
         })
         .show();
    }
}
